package cac.common;/*
 *@program:test-curd
 *@description:
 *@author: lsl
 *@Time: 2022/9/21  10:37
 */

import java.io.Serializable;

public class ReMsg<T> implements Serializable {
    private static final long serialVersionUID = 1234560319171014184L;
    private String Code = String.valueOf(200);
    private String errorDesc = "";
    private String msg = "";
    private String ok ="";
    private T data;
    private final long timestamp = System.currentTimeMillis();


    public ReMsg() {
    }

    public static <T> ReMsg<T> ok() {
        ReMsg<T> r = new ReMsg();
        r.setCode(String.valueOf(200));
        return r;
    }

    public static <T> ReMsg<T> ok(T data) {
        ReMsg<T> r = new ReMsg();
        r.setCode(String.valueOf(200));
        r.setData(data);
        return r;
    }

    public static <T> ReMsg<T> ok(String msg, T data){
        ReMsg<T> r =new ReMsg();
        r.setCode(String.valueOf(200));
        r.setData(data);
        r.setMsg(msg);
        return r;
    }

    public static <T> ReMsg<T> error(String msg) {
        return error(500, msg);
    }

    public static <T> ReMsg<T> error(int code, String msg){
        return error(code,msg,null);
    }

    public static <T> ReMsg<T> error(String msg, T data) {
        return error(500, msg, data);
    }

    public static <T> ReMsg<T> error(int code, String msg, T data) {
        ReMsg<T> r = new ReMsg();
        r.setCode(String.valueOf(code));
        r.setMsg(msg);
        r.setData(data);
        return r;
    }


    public String getok() {
        return ok;
    }

    public void setok(String ok) {
        this.ok = ok;
    }

    public String getCode() {
        return Code;
    }

    public void setCode(String code) {
        Code = code;
    }

    public String getErrorDesc() {
        return errorDesc;
    }

    public void setErrorDesc(String errorDesc) {
        this.errorDesc = errorDesc;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public long getTimestamp() {
        return timestamp;
    }

    @Override
    public String toString() {
        return "ReMsg{" +
                "Code='" + Code + '\'' +
                ", errorDesc='" + errorDesc + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                ", timestamp=" + timestamp +
                '}';
    }
}